export type Point = {
    x: number,
    y: number
}

export function drawDigit(graphic:CanvasRenderingContext2D,d:string,s:number,x:number,y:number,padding?:number,reverseY?:boolean){
    padding = padding||0;
    reverseY = reverseY||false;
    const x0 = x+padding;
    const x1 = x+padding+s;
    const y0 = reverseY?y+s*2-padding:y+padding;
    const y1 = y+s;
    const y2 = reverseY?y+padding:y+s*2-padding;
    switch(d){
        case "-":
            graphic.moveTo(x0,y1);
            graphic.lineTo(x1,y1);
            break;
        case "0":
            graphic.moveTo(x0,y0);
            graphic.lineTo(x1,y0);
            graphic.lineTo(x1,y2);
            graphic.lineTo(x0,y2);
            graphic.lineTo(x0,y0);
            break;
        case "1":
            graphic.moveTo(x1,y0);
            graphic.lineTo(x1,y2);
            break;
        case "2":
            graphic.moveTo(x0,y2);
            graphic.lineTo(x1,y2);
            graphic.lineTo(x1,y1);
            graphic.lineTo(x0,y1);
            graphic.lineTo(x0,y0);
            graphic.lineTo(x1,y0);
            break;
        case "3":
            graphic.moveTo(x0,y0);
            graphic.moveTo(x0,y2);
            graphic.lineTo(x1,y2);
            graphic.lineTo(x1,y0);
            graphic.lineTo(x0,y0);
            graphic.moveTo(x0,y1);
            graphic.lineTo(x1,y1);
            break;
        case "4":
            graphic.moveTo(x0,y2);
            graphic.lineTo(x0,y1);
            graphic.lineTo(x1,y1);
            graphic.moveTo(x1,y2);
            graphic.lineTo(x1,y0);
            break;
        case "5":
            graphic.moveTo(x1,y2);
            graphic.lineTo(x0,y2);
            graphic.lineTo(x0,y1);
            graphic.lineTo(x1,y1);
            graphic.lineTo(x1,y0);
            graphic.lineTo(x0,y0);
            break;
        case "6":
            graphic.moveTo(x1,y2);
            graphic.lineTo(x0,y2);
            graphic.lineTo(x0,y0);
            graphic.lineTo(x1,y0);
            graphic.lineTo(x1,y1);
            graphic.lineTo(x0,y1);
            break;
        case "7":
            graphic.moveTo(x1,y0);
            graphic.lineTo(x1,y2);
            graphic.moveTo(x0,y2);
            break;
        case "8":
            graphic.moveTo(x0,y0);
            graphic.lineTo(x1,y0);
            graphic.lineTo(x1,y2);
            graphic.lineTo(x0,y2);
            graphic.lineTo(x0,y0);
            graphic.moveTo(x0,y1);
            graphic.lineTo(x1,y1);
            break;
        case "9":
            graphic.moveTo(x0,y0);
            graphic.lineTo(x1,y0);
            graphic.lineTo(x1,y2);
            graphic.lineTo(x0,y2);
            graphic.lineTo(x0,y1);
            graphic.lineTo(x1,y1);
            break;
    }
}

function drawDigits(graphic:CanvasRenderingContext2D,str:string,s:number,x:number,y:number,margin?:number,padding?:number,reverseY?:boolean){
    margin = margin||0;
    let dx = margin;
    for(const d of str){
        drawDigit(graphic,d,s,x+dx,y,padding,reverseY);
        x += s+margin;
    }
}
